const compilerSFC = require('@vue/compiler-sfc');
const _ = require('lodash');

module.exports = function (resoures) {
  const sfc = compilerSFC.parse(resoures);
  let customBlocks = sfc.descriptor.customBlocks;

  let components = [];

  customBlocks.filter(item => {
    return item.type === 'import'
  }).forEach(({ attrs }) => {
    let { name, src } = attrs;
    let requireCode = `"${name}": require("${src}")`;
    components.push(requireCode);
  });

  let componentsCode = `{${components.join(',')}}`;

  return `
    module.exports = function() {
      return ${componentsCode};
    }
  `;
}